package com.igroupes.ovineherd.util;

public final class BooleanUtils extends org.apache.commons.lang3.BooleanUtils {
    private BooleanUtils() {
    }


    public static boolean toBool(Object o) {
        Requires.requireNonNull(o);
        Class clazz = o.getClass();
        if (clazz == Integer.class) {
            return BooleanUtils.toBoolean((Integer) o);
        } else if (clazz == String.class) {
            return BooleanUtils.toBoolean(o.toString());
        } else if(clazz == Boolean.class){
            return (Boolean)o;
        }{
            throw new UnsupportedOperationException();
        }
    }

    /**
     * 返回0/1
     *
     * @param o
     * @return
     */
    public static int toInt(Object o) {
        return toBool(o) ? 1 : 0;
    }



}
